home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / util / pack / xpk_Source.lha / xpk_Source / xpkmaster / hook.c < prev    next >
C/C++ Source or Header  |  1998-11-09  |  2KB  |  81 lines

  1. #ifndef XPKMASTER_HOOK_C
  2. #define XPKMASTER_HOOK_C
  3.  
  4. /* Routinesheader
  5.  
  6.     Name:        hook.c
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: hook.c 1.5 (13.09.1998)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    Hook handling functions
  12.  
  13.  1.0   05.10.96 : first real version
  14.  1.1   27.12.96 : removed V37 defines
  15.  1.2   20.12.97 : nearly rewritten
  16.  1.3   09.01.98 : added XPK_ALLINONE
  17.  1.4   26.08.98 : returns XPKERR_BADPARAMS, when no hook exists
  18.  1.5   13.09.98 : added seek support
  19. */
  20.  
  21. #include <exec/types.h>
  22. #include "xpkmaster.h"
  23.  
  24. #ifdef DEBUG
  25. static STRPTR action_names[8] =
  26. {"<zero>", "XIO_READ", "XIO_WRITE", "XIO_FREE", "XIO_ABORT", "XIO_GETBUF",
  27. "XIO_SEEK", "XIO_TOTSIZE" };
  28. #endif
  29.  
  30. static APTR callhook(struct XpkBuffer *xbuf, ULONG action, APTR buf,
  31. LONG size, struct XpkMasterMsg *msg, struct Hook *hook)
  32. {
  33.   LONG res;
  34.  
  35.   msg->xmm_Type = action;
  36.   msg->xmm_Ptr = (STRPTR) buf;
  37.   msg->xmm_Size = size;
  38.  
  39.   if(!hook)
  40.   {
  41.     xbuf->xb_Result = XPKERR_BADPARAMS;
  42.     return 0;
  43.   }
  44.  
  45.   if((res = (*(regfunc) hook->h_Entry) (hook, msg, 0 A4SUPP2)))
  46.   {
  47.     xbuf->xb_Result = res;
  48. #ifdef DEBUG
  49.     DebugError("hook%s: %s <%ld> (%ld)", msg == &xbuf->xb_RMsg ? "read" :
  50.     "write", action_names[(action&7)], action, xbuf->xb_Result);
  51. #endif
  52.   }
  53.  
  54.   if(xbuf->xb_Result)
  55.     return 0;
  56.   else if(msg->xmm_Ptr)
  57.     return (APTR) msg->xmm_Ptr;
  58.   else
  59.     return (APTR) -1; /* SEEK may return 0 on success! */
  60. }
  61.  
  62. /*************************** read from input hook ************************/
  63.  
  64. XPK_ALLINONE APTR hookread(struct XpkBuffer *xbuf, ULONG action, APTR buf,
  65. LONG size)
  66. {
  67.   if(action == XIO_READ || action == XIO_SEEK)
  68.     xbuf->xb_InBufferPos += size;
  69.   return callhook(xbuf, action, buf, size, &xbuf->xb_RMsg, xbuf->xb_RHook);
  70. }
  71.  
  72. /*************************** write to output hook ************************/
  73.  
  74. XPK_ALLINONE APTR hookwrite(struct XpkBuffer *xbuf, ULONG action, APTR buf,
  75. LONG size)
  76. {
  77.   return callhook(xbuf, action, buf, size, &xbuf->xb_WMsg, xbuf->xb_WHook);
  78. }
  79.  
  80. #endif /* XPKMASTER_HOOK_C */
  81.